<?php
class editAction extends rareAction{
    public function execute(){
        $id = $this->getGetParam('id',0);
        if($id == 0) forward('news/index');
        $newsDao = new DaoNews();
        $news = $newsDao->getOne("id = '$id'");
		
		$imgDao = new DaoImage();
		$images = $imgDao->getList("typeID='".service_type::NEWS."' and itemID='$id'");
		$this->assign('images',$images);
        $this->assign('news',$news);
    }
	public function executePost(){
		$news = $this->getPostParam('news',array());
		$id = $this->getPostParam('id',0);
		$images = $this->getPostParam('img',array());
		if($id==0) jsonReturn(0,"edit fail!");
		if(empty($news)) jsonReturn(0,'edit fail!');
		$newsDao = new DaoNews();
		$news['isIndex'] = 0;
		$now = date("Y-m-d H:i:s");
		$news['updateTime'] = $now;
		$re = $newsDao->update("id='$id'",$news);
		if(!empty($images)){
			service_image::insert($images,service_type::NEWS,$id);
		}
		if($re){
			jsonReturn(1,'ok');
		}else{
			jsonReturn(0,'fail');
		}
	}
}
?>
